﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace 数据库应用程序设计综合
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        bool isLogin = false;
        bool isNull = false;

        private void button1_Click(object sender, EventArgs e)
        {
            string str;
            OleDbConnection mycon = new OleDbConnection();
            str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Access数据库\21.mdb";
            mycon.ConnectionString = str;
            mycon.Open();
            OleDbCommand mycom = new OleDbCommand();
            string str3 = "select * from theUser ";
            mycom.CommandText = str3;
            mycom.Connection = mycon;
            OleDbDataReader myreader = mycom.ExecuteReader();
            //string str1 = myreader.GetString(2);
            //string str2 = myreader.GetString(3);
            //if (textBox1.Text == str1 && textBox2.Text == str2)
            //{
            //    MessageBox.Show("登录成功");
            //}
            //else
            //{
            //    MessageBox.Show("用户名或密码错误");
            //}
            //if (mycon.State == ConnectionState.Open)
            //{
            //    MessageBox.Show("连接成功");
            //}
            //else
            //    MessageBox.Show("连接失败");
            while (myreader.Read())
            {
                /* if (textBox1.Text != myreader.GetString(0))
                     MessageBox.Show("用户名不存在");
                 else if (textBox2.Text != myreader.GetString(1))
                     MessageBox.Show("请输入正确的密码");*/

                if (textBox1.Text != "" && textBox2.Text != "")
                {
                    string str1 = myreader.GetString(4);
                    string str2 = myreader.GetString(1);
                    if (textBox1.Text == str1 && textBox2.Text == str2)
                    {

                        Form2 form2 = new Form2();
                        form2.Show();
                        this.Hide();
                        isLogin = true;
                        break;
                    }
                    else
                    {
                        MessageBox.Show("验证错误");
                    }

                }
                else
                {
                    MessageBox.Show("请输入用户名或密码!");
                    isNull = true;
                    break;
                }
            }

            
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form1 f = new Form1();
            f = this;
            f.Close();
           
        }
    }
}
